package com.example.mobile2121606110syc0330homework2;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import javax.security.auth.login.LoginException;

public class MainActivity extends AppCompatActivity {

    private TextView textView;
    private EditText editTextTextPersonName;
    private EditText editTextTextPassword;
    private Button button;
    private Button button2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String Usename = "admin";
                String Upwd = "admin";
                String user = editTextTextPersonName.getText().toString();
                String psw = editTextTextPassword.getText().toString();
                if (user.equals(Usename) && psw.equals(Upwd)) {
                    Toast.makeText(MainActivity.this, "成功登录", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this, "账号或密码错误", Toast.LENGTH_SHORT).show();
                }
            }
        });
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editTextTextPersonName.setText("");
                editTextTextPassword.setText("");
            }
        });
    }


    private void initView() {
        textView = (TextView) findViewById(R.id.textView);
        editTextTextPersonName = (EditText) findViewById(R.id.editTextTextPersonName);
        editTextTextPassword = (EditText) findViewById(R.id.editTextTextPassword);
        button = (Button) findViewById(R.id.button);
        button2 = (Button) findViewById(R.id.button2);
    }
}